namespace TSL.Utility.Json
{
    using System;
    using System.Text;

    public class IJavaScriptObjectConverter : IJavaScriptConverter
    {
        public IJavaScriptObjectConverter()
        {
            base.m_serializableTypes = new Type[] { typeof(IJavaScriptObject), typeof(JavaScriptArray), typeof(JavaScriptBoolean), typeof(JavaScriptNumber), typeof(JavaScriptObject), typeof(JavaScriptString), typeof(JavaScriptSource) };
            base.m_deserializableTypes = base.m_serializableTypes;
        }

        public override object Deserialize(IJavaScriptObject o, Type t)
        {
            return o;
        }

        public override string Serialize(object o)
        {
            StringBuilder sb = new StringBuilder();
            this.Serialize(o, sb);
            return sb.ToString();
        }

        public override void Serialize(object o, StringBuilder sb)
        {
            JavaScriptObject obj2 = o as JavaScriptObject;
            if (obj2 == null)
            {
                sb.Append(((IJavaScriptObject) o).Value);
            }
            else
            {
                bool flag = true;
                sb.Append("{");
                foreach (string str in obj2.Keys)
                {
                    if (flag)
                    {
                        flag = false;
                    }
                    else
                    {
                        sb.Append(",");
                    }
                    JavaScriptUtil.QuoteString(str, sb);
                    sb.Append(":");
                    sb.Append(JavaScriptSerializer.Serialize(obj2[str]));
                }
                sb.Append("}");
            }
        }
    }
}

